<template>
  <div class="myView-page">
    <van-nav-bar title="我的" left-text="返回" left-arrow @click-left="$goBack" />
    <div class="main">
      <div class="headerrrrrrrr">
        <img src="../assets/myView.png" alt="">
        <span>登录名：{{ username }}</span> <!-- 显示用户名 -->
      </div>
      <router-Link to="/">
        <li class="wz">我的订单<van-icon name="arrow" class="jt" /></li>
      </router-Link>
      <router-Link to="/more">
        <li class="wz">关于我们<van-icon name="arrow" class="jt" /></li>
      </router-Link>
    </div>
    <!-- 底部导航栏 -->
    <BottomTabBar />
  </div>
</template>

<script>
import BottomTabBar from '@/components/BottomTabBar.vue';
export default {
  name: 'MyView',
  components: {
    BottomTabBar,
  },

  data() {
    return {
      username: this.getUsernameFromLocalStorage() || '未登录' // 如果没有用户名，则显示“未登录”
    }
  },

  created() {
    // 可以在这里添加其他初始化逻辑
  },

  methods: {
    getUsernameFromLocalStorage() {
      const userInfo = localStorage.getItem('userInfo');
      if (userInfo) {
        try {
          const parsedUserInfo = JSON.parse(userInfo);
          return parsedUserInfo.username;
        } catch (error) {
          console.error('Failed to parse userInfo from localStorage:', error);
          return null;
        }
      }
      return null;
    }
  }
}
</script>

<style scoped>
.myView-page {
  overflow: hidden;
  height: 100vh; /* 视口高度 */
}

.main {
  flex: 1;
}

.headerrrrrrrr {
  width: 95%;
  height: 110px;
  margin: 20px auto;
  background-color: #51c7c7;
  display: flex;
  align-items: center;
  border-radius: 7px;
}

span {
  color: white;
}

img {
  width: 60px;
  height: 60px;
  margin: 30px;
  border-radius: 30px;
}

li {
  height: 40px;
  border-bottom: 1px solid #e9e9e9;
  font-size: 15px;
  width: 95%;
  padding-left: 20px;
  display: flex;
  align-items: center;
  color: black;
}
.jt {
  padding-left: 260px;
}
.wz {
  width: 100%;
  padding-top: 5px;
}
</style>